%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Plot actual and cftl flows
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

figure, 

% Prime-age females
tp=mq(sum(jiu0(:,2:4),2));
tp_alt=mq(sum(jiu(:,2:4),2));

subplot(221), 
bar(1:length(nber),-1+max(0,5*nber),1,'EdgeColor',[.7,.7,.7],'FaceColor',[.7,.7,.7],'LineStyle','none','Clipping','on'),xlim([1 length(nber)])
h1=gca;
set(h1,'YAxisLocation','right','Color','white','XTickLabel',[]);
set(h1,'Fontsize',8)
h2=axes('Position',get(h1,'Position'));
set(h2,'Fontsize',8)
plot(hpfilter(tp,10),'LineWidth',2);
hold on, plot(hpfilter(tp_alt,10),'LineWidth',2,'LineStyle','--','Color',[0 .5 0]);
set(h2,'YAxisLocation','left','Color','none')
ylim(h1,[2 3]), set(h1,'Yticklabel',[]), set(h1,'YTick',[],'XTick',[])
% ylim(h2,[4 11])
set(gca,'FontSize',8)
set(gca','Xticklabel',num2str((1980:10:2015)'))
set(gca,'Xtick',4*4+1:4*10:length(tp)), xlim([1 length(tp)]),
ylabel('Women'), %ylim([-.8 .8])
title('NU')
legend('boxoff')

NUw=[hpfilter(tp,10) hpfilter(tp_alt,10)];


tp=mq(sum(jei0(:,2:4),2));
tp_alt=mq(sum(jei(:,2:4),2));

subplot(222), set(gca,'FontSize',8)
bar(1:length(nber),-1+max(0,5*nber),1,'EdgeColor',[.7,.7,.7],'FaceColor',[.7,.7,.7],'LineStyle','none','Clipping','on'),xlim([1 length(nber)])
h1=gca;
set(h1,'YAxisLocation','right','Color','white','XTickLabel',[]);
set(h1,'Fontsize',8)
h2=axes('Position',get(h1,'Position'));
set(h2,'Fontsize',8)
plot(hpfilter(tp,10),'LineWidth',2);
hold on, plot(hpfilter(tp_alt,10),'LineWidth',2,'LineStyle','--','Color',[0 .5 0]);
set(h2,'YAxisLocation','left','Color','none')
ylim(h1,[2 3]), set(h1,'Yticklabel',[]), set(h1,'YTick',[],'XTick',[])
% ylim(h2,[4 11])
set(gca','Xticklabel',num2str((1980:10:2015)'))
set(gca,'Xtick',4*4+1:4*10:length(tp)), xlim([1 length(tp)]),
ylabel('Women'), %ylim([-.8 .8])
legend('Actual','Counter-factual','Location','Best'), legend('boxoff')
title('EN')

ENw=[hpfilter(tp,10) hpfilter(tp_alt,10)];

% Young
tp=mq((jiu0(:,1)+jiu0(:,6))/2);
tp_alt=mq((jiu(:,1)+jiu(:,6))/2);

subplot(223), set(gca,'FontSize',8)
bar(1:length(nber),-1+max(0,5*nber),1,'EdgeColor',[.7,.7,.7],'FaceColor',[.7,.7,.7],'LineStyle','none','Clipping','on'),xlim([1 length(nber)])
h1=gca;
set(h1,'YAxisLocation','right','Color','white','XTickLabel',[]);
set(h1,'Fontsize',8)
h2=axes('Position',get(h1,'Position'));
set(h2,'Fontsize',8)
plot(hpfilter(tp,10),'LineWidth',2);
hold on, plot(hpfilter(tp_alt,10),'LineWidth',2,'LineStyle','--','Color',[0 .5 0]);
set(h2,'YAxisLocation','left','Color','none')
ylim(h1,[2 3]), set(h1,'Yticklabel',[]), set(h1,'YTick',[],'XTick',[])
set(gca','Xticklabel',num2str((1980:10:2015)'))
set(gca,'Xtick',4*4+1:4*10:length(tp)), xlim([1 length(tp)]),
ylabel('Young'), %ylim([-.8 .8])
title('NU')

NUyg=[hpfilter(tp,10) hpfilter(tp_alt,10)];


tp=mq((1*jui0(:,1)+jui0(:,6))/2);
tp_alt=mq((1*jui(:,1)+jui(:,6))/2);

subplot(224),  set(gca,'FontSize',8)
bar(1:length(nber),-1+max(0,5*nber),1,'EdgeColor',[.7,.7,.7],'FaceColor',[.7,.7,.7],'LineStyle','none','Clipping','on'),xlim([1 length(nber)])
h1=gca;
set(h1,'YAxisLocation','right','Color','white','XTickLabel',[]);
set(h1,'Fontsize',8)
h2=axes('Position',get(h1,'Position'));
set(h2,'Fontsize',8)
plot(hpfilter(tp,10),'LineWidth',2);
hold on, plot(hpfilter(tp_alt,10),'LineWidth',2,'LineStyle','--','Color',[0 .5 0]);
set(h2,'YAxisLocation','left','Color','none')
ylim(h1,[2 3]), set(h1,'Yticklabel',[]), set(h1,'YTick',[],'XTick',[])
set(gca','Xticklabel',num2str((1980:10:2015)'))
set(gca,'Xtick',4*4+1:4*10:length(tp)), xlim([1 length(tp)]),
ylabel('Young'), %ylim([-.8 .8])
title('UN')

UNyg=[hpfilter(tp,10) hpfilter(tp_alt,10)];

%Data for online appendix
qy([NUw ENw NUyg UNyg]);



